package com.li.design;  
/**  
* 类说明   
*  
* @author ****  
* @date 2018年4月1日  新建  
*/
public class Strategy {
	static class Context{
		OperationStrategy os = null;
		
		Context(){
			
		}
		public Context(OperationStrategy os){
			this.os = os;
		}
		public int executeStrategy(int a,int b){
			return os.operate(a, b);
		}
	}
	
	interface OperationStrategy{
		int operate(int a,int b);
	}
	
	static class AddStrategy implements OperationStrategy{

		@Override
		public int operate(int a, int b) {
			// TODO Auto-generated method stub
			return a+b;
		}
		
	}
	
	static class SubStrategy implements OperationStrategy{

		@Override
		public int operate(int a, int b) {
			// TODO Auto-generated method stub
			return a-b;
		}
		
	}
	
	public static void main(String[] args) {
		Context c = new Context(new AddStrategy());
		System.out.println(c.executeStrategy(1, 2));
	}
}
  